/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: GoldenSpringSocialConfigurer
 * Author:   zhouheng
 * Date:     2019/6/15 14:24
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.security.social;

import com.zhouh.golden.security.handler.GoldenAuthenticationSucessHandler;
import com.zhouh.golden.security.properties.GoldenSecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.social.security.SpringSocialConfigurer;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author zhouheng
 * @create 2019/6/15
 * @since 1.0.0
 */
public class GoldenSpringSocialConfigurer extends SpringSocialConfigurer {
    private String filterProcessesUrl;

    private GoldenSecurityProperties goldenSecurityProperties;

    private GoldenAuthenticationSucessHandler goldenAuthenticationSucessHandler;

    public GoldenSpringSocialConfigurer(String filterProcessesUrl) {
        this.filterProcessesUrl = filterProcessesUrl;
    }

    /**
     * @description: 重写请求授权url
     * @date: 2019/6/15 14:27
     * @author:zhouheng
     */
    @Override
    protected Object postProcess(Object object) {
        SocialAuthenticationFilter socialAuthenticationFilter = (SocialAuthenticationFilter)super.postProcess(object);
        socialAuthenticationFilter.setFilterProcessesUrl(filterProcessesUrl);
        socialAuthenticationFilter.setSignupUrl(goldenSecurityProperties.getSocial().getSocialRedirectUrl());
        socialAuthenticationFilter.setAuthenticationSuccessHandler(goldenAuthenticationSucessHandler);

        return socialAuthenticationFilter;
    }

    public void setGoldenSecurityProperties(GoldenSecurityProperties goldenSecurityProperties) {
        this.goldenSecurityProperties = goldenSecurityProperties;
    }

    public void setGoldenAuthenticationSucessHandler(GoldenAuthenticationSucessHandler goldenAuthenticationSucessHandler) {
        this.goldenAuthenticationSucessHandler = goldenAuthenticationSucessHandler;
    }
}